package baseFx.common.caching;

import baseFx.common.Action1T;

public interface Cache {
    void save(CacheItem item);

    void remove(String key);

    void update(String key, Object value);

    boolean exists(String key);

    Object get(String key);

    default void save(String key, Object value, int absoluteExpiration) {
        CacheItem item = new CacheItem();
        item.key = key;
        item.value = value;
        item.absoluteExpiration = absoluteExpiration;
        save(item);
    }

    default void save(Action1T<CacheItem> action) {
        CacheItem item = new CacheItem();
        action.execute(item);
        save(item);
    }
}
